package com.tencreat.mall.controller.admin;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tencreat.common.annotation.Log;
import com.tencreat.common.core.HttpResult;
import com.tencreat.common.core.controller.BaseController;
import com.tencreat.common.core.domain.AjaxResult;
import com.tencreat.common.core.domain.model.ReqIdParam;
import com.tencreat.common.core.domain.model.ReqIdsParam;
import com.tencreat.common.enums.BusinessType;
import com.tencreat.common.utils.poi.ExcelUtil;
import com.tencreat.domain.mall.MallSelfmention;
import com.tencreat.service.mall.IMallSelfmentionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * 自提地址Controller
 *
 * @author tencreat
 * @date 2022-01-05
 */
@Api(tags="自提地址api")
@RestController
@RequestMapping("/system/selfmention")
public class AdminMallSelfmentionController extends BaseController {
    @Autowired
    private IMallSelfmentionService mallSelfmentionService;

    /**
     * 查询自提地址列表
     */
    @ApiOperation(value="查询自提地址列表")
    @PostMapping("/list")
    public HttpResult<IPage<MallSelfmention>> list(@RequestBody MallSelfmention mallSelfmention) {
        QueryWrapper<MallSelfmention> wrapper = Wrappers.query(mallSelfmention);
        Page<MallSelfmention> page =  new Page<>(mallSelfmention.getPageNum(), mallSelfmention.getPageSize());
        return HttpResult.ok(mallSelfmentionService.page(page, wrapper));
    }
    /**
     * 查询自提地址列表
     */
    @ApiOperation(value="查询自提地址列表 无分页")
    @PostMapping("/allList")
    public HttpResult<List<MallSelfmention>> allList() {
        return HttpResult.ok(mallSelfmentionService.lambdaQuery().list());
    }
    /**
     * 导出自提地址列表
     */
    @ApiOperation(value="导出自提地址列表")
    @PreAuthorize("@ss.hasPermi('system:selfmention:export')")
    @Log(title = "基础配置>快递配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public AjaxResult export(MallSelfmention mallSelfmention) {
        List<MallSelfmention> list = mallSelfmentionService.selectMallSelfmentionList(mallSelfmention);
        ExcelUtil<MallSelfmention> util = new ExcelUtil<MallSelfmention>(MallSelfmention.class);
        return util.exportExcel(list, "selfmention");
    }

    /**
     * 获取自提地址详细信息
     */
    @ApiOperation(value="获取自提地址详细信息")
    @PreAuthorize("@ss.hasPermi('system:selfmention:query')")
    @PostMapping(value = "/getInfo")
    public HttpResult<MallSelfmention> getInfo(@RequestBody   ReqIdParam id) {
        return HttpResult.ok(mallSelfmentionService.selectMallSelfmentionById(id));
    }

    /**
     * 新增自提地址
     */
    @ApiOperation(value="新增自提地址")
    @PreAuthorize("@ss.hasPermi('system:selfmention:add')")
    @Log(title = "基础配置>快递配置", businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    public HttpResult<Boolean> add(@RequestBody  MallSelfmention mallSelfmention) {
        return to(mallSelfmentionService.insertMallSelfmention(mallSelfmention));
    }

    /**
     * 修改自提地址
     */
    @ApiOperation(value="修改自提地址")
    @PreAuthorize("@ss.hasPermi('system:selfmention:edit')")
    @Log(title = "基础配置>快递配置", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/edit")
    public HttpResult<Boolean> edit(@RequestBody  MallSelfmention mallSelfmention) {
        return to(mallSelfmentionService.updateMallSelfmention(mallSelfmention));
    }

    /**
     * 删除自提地址
     */
    @ApiOperation(value="删除自提地址")
    @PreAuthorize("@ss.hasPermi('system:selfmention:remove')")
    @Log(title = "基础配置>快递配置", businessType = BusinessType.DELETE)
	@PostMapping("/remove")
    public HttpResult<Boolean> remove(@RequestBody  ReqIdsParam ids) {
        return to(mallSelfmentionService.deleteMallSelfmentionByIds(ids));
    }
}
